<?php
defined('PT_ACCESS') or die('No direct access');

spl_autoload_register('spl_autoload_custom');

/**
 * Does the same as spl_autoload, but without lowercasing
 */
function spl_autoload_custom($name){
	$rc = FALSE;

	$exts = explode(',', spl_autoload_extensions());
	$paths = explode(PATH_SEPARATOR, ini_get('include_path'));

	foreach ($paths as $path){
		foreach ($exts as $ext){
			$file = $path . DS . $name . $ext;
			if (is_readable($file)){
				require_once $file;
				$rc = $file;
				break;
			}
		}
	}

	return $rc;
}

class autoloader{

	public static $loader;

	public static function init(){
		if (self::$loader == NULL)
			self::$loader = new self();

		return self::$loader;
	}

	public function __construct(){
		set_include_path(get_include_path() . PATH_SEPARATOR
		.DIR_SYSTEM . PATH_SEPARATOR
		.DIR_SYSTEM . 'filter/' . PATH_SEPARATOR
		.DIR_SYSTEM . 'user/' . PATH_SEPARATOR
		.DIR_SYSTEM . 'controllers/' . PATH_SEPARATOR
		.DATABASE . PATH_SEPARATOR
		.DIR_CONFIG . PATH_SEPARATOR
		.DIR_LIBRARY . PATH_SEPARATOR
		.DIR_CONTROLLERS . PATH_SEPARATOR
		.DIR_MODEL . PATH_SEPARATOR
		.DIR_MODEL_ADMIN . PATH_SEPARATOR
		.DIR_LIBRARY . 'Smarty/' . PATH_SEPARATOR
		);

		spl_autoload_extensions(".inc,.php,.lib,.lib.php,.class.php");
		spl_autoload_register(array(
				$this,
				'loader'
		));

	}

	public function loader($class){
		spl_autoload($class);
	}
}

//call
autoloader::init();